<?php


include 'db-login.php';

//Performing SQL query
//Select all of the prescription medications from the pharmacy
//database that are still being taken and were picked up in the last 6
//months
//Assume you cannot write to pharmacy
$query = 'SELECT * FROM pharmacy WHERE MedicationType = \'prescription\' AND EffectiveEndDate is NULL AND DATE_ADD(CURRENT_DATE, INTERVAL -6 MONTH) < EffectiveStartDate;';

$MedListQuery = 'SELECT * FROM medications WHERE MedicationType = \'prescription\' AND EffectiveEndDate is NULL AND DATE_ADD(CURRENT_DATE, INTERVAL -6 MONTH) < EffectiveStartDate;';

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

$MedListResult = mysql_query($MedListQuery) or die('Query failed: ' . mysql_error());

// Printing Results in Medication Page for prescriptions-select.php -
// part of wizard
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

  $value = $row['MedicationType'].".".$row['MedicationSubType'].".".$row['MedicationIdentity'].".".$row['GenericIngredients'].".".$row['UnitStrength'].".".$row['DosageForm'].".".$row['Route'].".".$row['DispensedQuantitity'].".".$row['RefillsAuthorized'].".".$row['DosingFrequency'].".".$row['DosingQuantity'].".".$row['DosingInstructions'].".".$row['FullTextDescription'].".".$row['OutOfPocketCostUS'].".".$row['AnnotationReferences'].".".$row['DosingStatus'].".".$row['EffectiveStartDate'].".".$row['EffectiveEndDate'].".".$row['Provenance'].".".$row['inList'];

 echo $value;

  echo "<div id=\"one-med\">";

  echo $row['inList']."<BR>";
  if ($row['inList'] == 1){
  echo "<input class=\"floatleft\" type=\"checkbox\" name=\"RxMeds[]\" value=\"".$value."\" checked>";
} else {

  echo "<input class=\"floatleft\" type=\"checkbox\" name=\"RxMeds[]\" value=\"".$value."\">";
}
  // Assuming file names for medications are named with the MedID & jpg form
  $filename = "./pics/".$row['MedicationIdentity'].".jpg";

  if (file_exists($filename)){
    echo "<img class=\"floatleft\" src=\"".$filename."\" alt=\"".$row['MedicationIdentity']."\" height=\"100\">";
  } else {
    echo "<div class=\"NABox\">N/A</div>";
  }
  echo "<p class=\"floatleft\">".$row['MedicationIdentity']."<BR>".$row['GenericIngredients']."<BR>".$row['UnitStrength']."</p></div>\n\n";
}
include './includes/db-close.php';

?>